//
//  LSZHelpTableViewCell.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/15.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZHelpTableViewCell.h"

@implementation LSZHelpTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.labelTitle = [[UILabel alloc]init];
        self.labelTitle.textColor = RGBColor(121, 121, 121);
        self.labelTitle.frame = CGRectMake(20, 10, ScreenWidth-40, 25);
        self.labelTitle.font = FONT_(18);
        [self addSubview:self.labelTitle];
        
        self.imageViewType = [[UIImageView alloc]init];
        self.imageViewType.frame = CGRectMake(ScreenWidth-40-5, 0, 40, 40);
        [self addSubview:self.imageViewType];

        
        self.labelTime = [[UILabel alloc]init];
        self.labelTime.frame = CGRectMake(20, CGRectGetMaxY(self.labelTitle.frame)+13, ScreenWidth/2, 14);
        self.labelTime.font = FONT_(12);
         self.labelTime.textColor = lightColor;
        [self addSubview:self.labelTime];
        
        self.labelNumber = [[UILabel alloc]init];
        self.labelNumber.frame =CGRectMake(CGRectGetMaxX(self.labelTime.frame), CGRectGetMinY(self.labelTime.frame), ScreenWidth-20-CGRectGetMaxX(self.labelTime.frame), self.labelTime.frame.size.height);
        self.labelNumber.textColor = lightColor;
        self.labelNumber.font = FONT_(12);
        self.labelNumber.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.labelNumber];
        [self addBorderToLayer:self];

    }
    return self;
}
- (void)setMutualProblemManager:(LSZMutualProblemMg *)mutualProblemManager
{
    self.labelTitle.text = mutualProblemManager.content;
    self.labelTime.text = mutualProblemManager.publishTime;
    self.labelNumber.text = [NSString stringWithFormat:@"%@条回答",mutualProblemManager.answerCount];
    if ([mutualProblemManager.solved isEqualToString:@"true"]) {
        self.imageViewType.image = [UIImage imageNamed:@"已解决"];
    }else{
        self.imageViewType.image = [UIImage imageNamed:@"进行中"];
    }
}
#pragma mark - 画虚线
- (void)addBorderToLayer:(UIView *)view
{
    CAShapeLayer *border = [CAShapeLayer layer];
    //  线条颜色
    border.strokeColor = lightColor.CGColor;
    border.fillColor = nil;
    UIBezierPath *pat = [UIBezierPath bezierPath];
    [pat moveToPoint:CGPointMake(10, CGRectGetMaxY(self.labelTitle.frame)+8)];
    if (CGRectGetWidth(view.frame) > CGRectGetHeight(view.frame)) {
        [pat addLineToPoint:CGPointMake(ScreenWidth-20, CGRectGetMaxY(self.labelTitle.frame)+8)];
    }else{
        [pat addLineToPoint:CGPointMake(CGRectGetMaxY(self.labelTitle.frame)+8,ScreenWidth-20)];
    }
    border.path = pat.CGPath;
    border.frame = view.bounds;
    // 不要设太大 不然看不出效果
    border.lineWidth = 0.5;
    border.lineCap = @"butt";
    //  第一个是 线条长度   第二个是间距    nil时为实线
    border.lineDashPattern = @[@6, @10];
    [view.layer addSublayer:border];
}
@end
